#!/bin/bash

databaseName=CRM_xxx
file_dir=/mnt/mysql/data_bak
if [ ! -d "$file_dir/" ]; then
    mkdir -p $file_dir
fi

file=$file_dir/$databaseName

fpath=$file_$(date +%Y%m%d_%H%M%S).sql

if [ ! -d $file ]; then
	mkdir $file;
fi


echo "===$databaseName备份 start==="
mysqldump -uroot -p1a2b3c4d!@# $databaseName > $fpath ;
echo "===$databaseName备份 end==="

if [ -f "$fpath" ]; then
    find $file/ -mtime +7 -name "*.sql" -exec rm -rf {} \;
    echo "===$databaseName七天前的备份已删除==="
fi

exit 0